package com.twu.biblioteca;

import com.twu.biblioteca.behavior.Behavior;
import com.twu.biblioteca.behavior.QuitBehavior;
import com.twu.biblioteca.behavior.WelcomeBehavior;

import java.io.InputStream;
import java.io.PrintStream;

public class BibliotecaApp {

    public BibliotecaApp(InputStream in, PrintStream out) {
        System.setIn(in);
        System.setOut(out);
    }

    public void start() {
        setLibrary();
        setTheater();
        setUsers();

        Behavior behavior = new WelcomeBehavior();

        while (!(behavior instanceof QuitBehavior)) {
            behavior.execute();
            behavior = behavior.nextBehavior();
        }
    }

    private void setLibrary() {
        Library library = Library.getInstance();
        library.addBook(new Book().author("author").title("title"));
        library.addBook(new Book().author("author2").title("title2"));
    }

    private void setTheater() {
        Theater theater = Theater.getInstance();

        theater.addMovie(new Movie().name("The Shawshank Redemption").director("Frank Darabont").year(1994).rating(10));
        theater.addMovie(new Movie().name("The Godfather").director("Francis Ford Coppola").year(1972).rating(10));
        theater.addMovie(new Movie().name("The Godfather: Part II").director("Francis Ford Coppola").year(1974).rating(9));
        theater.addMovie(new Movie().name("Pulp Fiction").director("Quentin Tarantino").year(1994).rating(9));
        theater.addMovie(new Movie().name("The Good, the Bad and the Ugly").director("Sergio Leone").year(1966).rating(9));
        theater.addMovie(new Movie().name("The Dark Knight").director("Christopher Nolan").year(2008).rating(9));
        theater.addMovie(new Movie().name("Angry Men").director("Sidney Lumet").year(1957).rating(8));
        theater.addMovie(new Movie().name("Schindler's List").director("Steven Spielberg").year(1993).rating(8));
        theater.addMovie(new Movie().name("The Lord of the Rings: The Return of the King").director("Peter Jackson").year(2003).rating(8));
        theater.addMovie(new Movie().name("Fight Club").director("David Fincher").year(1999).rating(8));
        theater.addMovie(new Movie().name("Star Wars: Episode V - The Empire Strikes Back").director("Irvin Kershner").year(1980).rating(7));
        theater.addMovie(new Movie().name("The Lord of the Rings: The Fellowship of the Ring").director("Peter Jackson").year(2001).rating(7));
        theater.addMovie(new Movie().name("One Flew Over the Cuckoo's Nest").director("Milos Forman").year(1975).rating(7));
        theater.addMovie(new Movie().name("Inception").director("Christopher Nolan").year(2010).rating(7));
        theater.addMovie(new Movie().name("Goodfellas").director("Martin Scorsese").year(1990));
    }

    private void setUsers() {
        UserCenter userCenter = UserCenter.getInstance();
        userCenter.addUserWithDefaultUsernameAndPassword(new User().email("yaodan.zhang@gmail.com"));
        userCenter.addUserWithDefaultUsernameAndPassword(new User().email("ydzhang@thoughtworks.com"));
        userCenter.addUserWithDefaultUsernameAndPassword(new User().email("zydjj007cn2005@163.com"));
        userCenter.addUserWithDefaultUsernameAndPassword(new User().email("375077912@qq.com"));
    }
}
